package com.wang;

import java.security.Key;
import java.util.Comparator;
import java.util.TreeMap;

/**
 * @ProjectName: untitled
 * @Titile: TreeMapDemo
 * @Author: 王亦凡1
 * @Description: TODO
 */
public class TreeMapDemo {
    public static void main(String[] args) {

    }
    public static void test1(){
        TreeMap<Student,String>treeMap=new TreeMap<>();
        treeMap.put(new Student("小赵",20),"深圳");
        treeMap.put(new Student("小王",20),"北京");
        treeMap.put(new Student("小李",20),"上海");
        treeMap.put(new Student("小非",20),"江苏");
        treeMap.put(new Student("小赵",20),"沈阳");

        treeMap.forEach((k,v)->System.out.println(k+"-"+v));
    }
    public static void test2(){

        TreeMap<Student, String> treeMap=new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getAge()- o1.getAge();
            }
        });
        treeMap.put(new Student("小赵",20),"深圳");
        treeMap.put(new Student("小王",20),"北京");
        treeMap.put(new Student("小李",20),"上海");
        treeMap.put(new Student("小非",20),"江苏");
        treeMap.put(new Student("小赵",20),"沈阳");
        treeMap.forEach((k,v)->System.out.println(k+"-"+v));
    }

}
